package com.cskaoyan._05servlet_3forwordredirect;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

/**
 * @author Macro_Ray
 * @since 2024/5/3 下午10:15
 */
// 响应重定向1
@WebServlet("/servlet1")
public class Servlet1 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 接受用户请求
        System.out.println("Servlet1 执行了");

        // 响应重定向
        response.sendRedirect("servlet2");   // 设置响应状态码为302，并将请求重定向到servlet2
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
